
    public class p2 {
        public static int m(int[] nums) {
            int m1 = nums[0];
            int m2 = nums[0];

            for (int i = 1; i < nums.length; i++) {
                m2 = Math.max(nums[i], m2 + nums[i]);
                m1 = Math.max(m1, m2);
            }
            return m1;
        }

        public static void main(String[] args) {
            int[] arr1 = {1, -2, 3, 5, -1};
            int[] arr2 = {1, -2, 3, -8, 5, 1};
            int[] arr3 = {1, -2, 3, -2, 5, 1};

            System.out.println("最大子数组和（数组1）： " + m(arr1));
            System.out.println("最大子数组和（数组2）： " + m(arr2));
            System.out.println("最大子数组和（数组3）： " + m(arr3));
        }
    }


